A blend mode is a formula used in combining a color of a source primitive with a color of a destination primitive to produce a new color in a rendered primitive. A primitive is the simplest object that typical graphics processing units draw, and primitives may be combined to form more robust images, shapes, backgrounds, graphics, etc. A source primitive may be a primitive that is rendered atop of an existing primitive, and a destination primitive may be the existing primitive. When using a particular blend mode to render a source primitive into a destination primitive, the blend mode may be applied to each pixel of the source and destination primitives. In this way, a blend mode may be applied to each pixel of a source and of a destination primitive to calculate a new color for each pixel of a rendered primitive.
A color of a pixel may be described by a combination of four components. Three of the components may represent the amount of red R, green G, and blue B in the color. These components may be labeled R, G, and B, each of which may be a floating-point number ranging from 0 to 1. A fourth component may be an alpha A value and may represent an opacity of a pixel. An alpha A value of 0 may describe the pixel as transparent, an alpha A value of 1 may describe the pixel as opaque, and a fractional alpha A value may describe a degree of translucence of the pixel. The four values of R, G, B, and A thus may define a pixel's color and opacity.
Formulas for blend modes may be written in a variety of ways. Graphics processing units may provide built-in support for a formula that computes components of a new color N from components of a source color S and a destination color D. The formulas may include parameters, P and Q, which may determine how a blend mode behaves. A parameter P, called a “source blend factor,” may be chosen from a set {0, 1, DA, 1−DA, DC, 1−DC}. Similarly, a parameter Q, called a “destination blend factor,” may be chosen from a set {0, 1, SA, 1−SA, SC, 1−SC}. Blend modes that may be built in a graphics processing unit to produce a new color or opacity N for each pixel may include:NR=P·SR+Q·DRNG=P·SG+Q·DGNB=P·SB+Q·DBNA=P·SA+Q·DA
Blend modes may be achieved using the P and Q parameters, as listed in the following table, Table 1:
TABLE 1Example values for parameters P and QBlend modePQClear00Source10Destination01Source Over11 − SADestination Over1 − DA1Source InDA0Destination In0SASource Out1 − DA0Destination Out01 − SASource AtopDA1 − SADestination Atop1 − DASAExclusive Or1 − DA1 − SAAdd11Screen1 − DC1
Parameters in addition to P and Q may be added to blend modes to provide additional variations for blend modes. For example, parameters X, Y, and Z may be used and may be constants with values of 0 or 1. When compositing an opaque source primitive with an opaque destination primitive, X may determine whether an intersection of the source and destination appears in a composite primitive, Y may determine whether a part of the source primitive outside the destination primitive appears, and Z may determine whether a part of the destination primitive outside the source primitive appears. A function f may be a function of the source and destination colors. The following equations may provide a more general formulation of blend modes, again computing a new color or opacity N from a given source color S and destination color D for each pixel:NR=f(SR, SA, DR, DA)+Y·SR·(1−DA)+Z·DR·(1−SA)NG=f(SG, SA, DG, DA)+Y·SG·(1−DA)+Z·DG·(1−SA)NB=f(SB, SA, DB, DA)+Y·SB·(1−DA)+Z·DB·(1−SA)NA=X·SA·DA+Y·SA·(1−DA)+Z·DA·(1−SA)
Some blend modes may be included with, for example, drivers for a graphics processing unit, and other blend modes may be supplied by a graphics application program. Example parameter values for such blend modes are listed in the following table, Table 2:
TABLE 2Example parameters for general blend formulasBlend modef(SC, SA, DC, DA)XYZClear0000SourceSC · DA110DestinationDC · SA101Source OverSC · DA111Destination OverDC · SA111Source InSC · DA100Destination InDC · SA100Source Out0010Destination Out0001Source AtopSC · DA101Destination AtopDC · SA110Exclusive Or0011AddSC · DA + DC · SA111ScreenSC · DA + DC · SA − SC · DC111MultiplySC · DC111Overlay2 · SC · DC, if 2 · DC < DA;111SC · DC − 2 · (DA − DC) · (SA − SC), otherwiseLightenmax(SC · DA, DC · SA)111Darkenmin(SC · DA, DC · SA)111Color DodgeSA · DA, if SC · DA + DC · SA ≧ SA · DA;111DC · SA/(1 − SC/SA), otherwiseColor Burn0, if SC · DA + DC · SA ≦ SA · DA;111SA · (SC · DA + DC · SA − SA · DA)/SC, otherwiseHard Light2 · SC · DC, if 2 · SC < SA;111SA · DA − 2 · (DA − DC) · (SA − SC), otherwiseSoft LightDC · (SA − (1 − DC/DA) · (2 · SC − SA)), if 2 · SC < SA;111DC · (SA − (1 − DC/DA) · (2 · SC − SA) · (3 − 8 · DC/DA)), if 8 ·DC ≦ DA;DC · SA + (DA · (DC/DA)0.5 − DC) · (2 · SC − SA), otherwiseDifferenceabs(SC · DA − DC · SA)111ExclusionSC · DA + DC · SA − 2 · SC · DC111
Typically, graphics processing units apply a few blend modes. For more complex or varied blend modes, graphics application programs may perform some or all of their rendering calculations through software on a central processing unit. That is, the central processing unit may perform the blending of two primitives and then send a bitmap to the graphics processing unit for rendering. The speed of execution of graphics application programs therefore may be limited by the rendering speed at which the central processing unit can render pixels of a composite primitive. The rendering speed of a central processing unit may be slower than the rendering speed of the graphics processing unit.
For example, a graphics application program may specify that a particular primitive, when drawn atop other primitives, should darken the colors of the other primitives. The amount of darkening applied to the existing primitives may be controlled by a luminance of the newly drawn primitive according to a blend mode. Typically, blend modes may be applied by the central processing unit for each pixel covered by the new primitive in the composite rendering.
Using the central processing unit to apply a blend mode pixel by pixel may slow application executions as the rendering process is completed. Additionally, central processing units may be pulled from completing other work to apply the blend mode, thus potentially slowing the performance of other tasks. In a client-server scenario, the server central processing unit may apply the blend mode and then transmit all the pixels of a composite primitive from the server to the client, consuming valuable bandwidth.
There is a need, therefore, for methods and apparatus for more efficiently rendering blend modes while taking advantage of the speed of a graphics processing unit. The methods and apparatus additionally should minimize the volume of calculations required of a central processing unit and the bandwidth required in the rendering process.